package com.hyfd.service.mp;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyfd.common.BaseJson;
import com.hyfd.dao.mp.AgentBillDiscountDao;
import com.hyfd.dao.mp.AgentDataDiscountDao;
import com.hyfd.dao.mp.BillPkgDao;
import com.hyfd.dao.mp.DataPkgDao;
import com.hyfd.dao.mp.PhoneSectionDao;
import com.hyfd.dao.mp.ProviderDao;
import com.hyfd.service.BaseService;


@Service
public class BillChargeSer extends BaseService{
	
	public Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private PhoneSectionSer phoneSectionSer;
	@Autowired
	PhoneSectionDao phoneSectionDao;
	@Autowired
	BillPkgDao billPkgDao;
	@Autowired
	ProviderDao providerDao;
	@Autowired
	AgentBillDiscountDao agentBillDiscountDao;
	
	
	/**
	 * 根据手机号查询号段、流量包信息
	 * */
	public String sectionAndBillPkgGet(HttpServletRequest req) {
		String str = null;
		try {
			Map<String, Object> m = getMaps(req);
			String phone = (String) m.get("phone");
			// 获取手机号相关信息
			String section = (phone.length() == 13) ? phone.substring(0, 5)
					: phone.substring(0, 7);// 获取号段
			Map<String, Object> sectionMessage = phoneSectionDao
					.selectBySection(section);
			if (sectionMessage != null) {
				Map<String, Object> agent = agentGetByUserId();
				String agentId = (String) agent.get("id");
				m.put("agentId", agentId);
				String agentName = (String) agent.get("name");
				sectionMessage.put("agentName", agentName);
				String providerId = (String) sectionMessage.get("provider_id");
				String providerName = providerDao.getNameById(providerId);
				sectionMessage.put("providerName", providerName);
				m.put("providerId", providerId);
				List<Map<String, Object>> pkgIdList = agentBillDiscountDao.getAgentDataDiscountPkgList(m);
				sectionMessage.put("dataPkgMessage", pkgIdList);
			}
			str = BaseJson.mapToJson(sectionMessage);
		} catch (Exception e) {
			getMyLog(e, log);
		}
		return str;
	}
}
